From 48a685b4cb8255fd59c922ec4c3e00d39e2c4c93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 19 Nov 2016 18:50:11 +0100 Subject: [PATCH] fast-float: indentation --- extensions/fast-float.c | 60 +++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/extensions/fast-float.c b/extensions/fast-float.c index 7ee725a..c76edfa 100644 --- a/extensions/fast-float.c +++ b/extensions/fast-float.c @@ -61,19 +61,17 @@ static inline float babl_lookup (BablLookup *lookup, float number) { - union { float f; uint32_t i; } u; - union { float f; uint32_t i; } ub; - union { float f; uint32_t i; } ua; - + union { float f; uint32_t i; } u; + union { float f; uint32_t i; } ua; + union { float f; uint32_t i; } ub; uint32_t i; - float dx = 0.0; u.f = number; i = (u.i << LSHIFT ) >> lookup->shift; if (i > lookup->positive_min && i < lookup->positive_max) { - ua.i = ((i) << lookup->shift) >> LSHIFT; + ua.i = ((i ) << lookup->shift) >> LSHIFT; ub.i = ((i+ 1) << lookup->shift) >> LSHIFT; i = i - lookup->positive_min; @@ -91,23 +89,22 @@ babl_lookup (BablLookup *lookup, return lookup->function (number, lookup->data); } - { - uint32_t bm =u.i & 0b11110000000000000000000000000000; - ua.i |= bm; - ub.i |= bm; - } - dx = (u.f-ua.f) / (ub.f - ua.f); - - { + ua.i |= 0b11110000000000000000000000000000; if (!(lookup->bitmask[i/32] & (1UL<<(i & 31)))) { lookup->table[i]= lookup->function (ua.f, lookup->data); lookup->bitmask[i/32] |= (1UL<<(i & 31)); } - i++; - if (i< lookup->entries-2) + + if (i< lookup->entries-1) { + float dx; + + ub.i |= 0b11110000000000000000000000000000; + dx = (u.f-ua.f) / (ub.f - ua.f); + + i++; if (!(lookup->bitmask[i/32] & (1UL<<(i & 31)))) { lookup->table[i]= lookup->function (ub.f, lookup->data); @@ -119,8 +116,7 @@ babl_lookup (BablLookup *lookup, } else { - return lookup->table[i-1]; - } + return lookup->table[i]; } } @@ -158,7 +154,8 @@ babl_lookup_new (BablLookupFunction function, else if (precision <= 0.000649) shift = 15; else shift = 16; /* a bit better than 8bit sRGB quality */ - shift = 16; + shift = 17; /* hard-coded decrease to slow down and increase precision, + increase to speed up and decease precision */ /* Adjust slightly away from 0.0, saving many entries close to 0, this * causes lookups very close to zero to be passed directly to the @@ -235,9 +232,9 @@ babl_lookup_new (BablLookupFunction function, positive_max-=diff; } - lookup = calloc (sizeof (BablLookup) + sizeof (float) * - ((positive_max-positive_min)+ - (negative_max-negative_min)), 1); + lookup = calloc (sizeof (BablLookup) + + sizeof (float) * ((positive_max-positive_min)+ + (negative_max-negative_min)), 1); lookup->positive_min = positive_min; lookup->positive_max = positive_max; @@ -333,7 +330,7 @@ conv_rgbaF_linear_rgbA8_gamma (unsigned char *src, unsigned char *dst, long samples) { - float *fsrc = (float *) src; + float *fsrc = (float *) src; uint8_t *cdst = (uint8_t *) dst; int n = samples; @@ -347,10 +344,13 @@ conv_rgbaF_linear_rgbA8_gamma (unsigned char *src, { int val = linear_to_gamma_2_2_lut (red) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (green) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (blue) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + *cdst++ = 0xff; } else if (alpha <= 0.0) @@ -361,12 +361,16 @@ conv_rgbaF_linear_rgbA8_gamma (unsigned char *src, else { float balpha = alpha * 0xff; + int val = linear_to_gamma_2_2_lut (red) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (green) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (blue) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + *cdst++ = balpha + 0.5f; } } @@ -392,10 +396,13 @@ conv_rgbaF_linear_rgbA8_gamma_cairo (unsigned char *src, { int val = linear_to_gamma_2_2_lut (blue) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (green) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (red) * 0xff + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + *cdst++ = 0xff; } else if (alpha <= 0.0) @@ -406,12 +413,16 @@ conv_rgbaF_linear_rgbA8_gamma_cairo (unsigned char *src, else { float balpha = alpha * 0xff; + int val = linear_to_gamma_2_2_lut (blue) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (green) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = linear_to_gamma_2_2_lut (red) * balpha + 0.5f; *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + *cdst++ = balpha + 0.5f; } } @@ -616,8 +627,6 @@ init (void) f = 2; } - - { const Babl *f32 = babl_format_new ( "name", "cairo-ARGB32", @@ -653,4 +662,3 @@ destroy (void) free (fast_rpow); free (fast_pow); } - -- 2.30.2